package com.zxh.zhenxihuan.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.zxh.zhenxihuan.entity.ShopCar;
import com.zxh.zhenxihuan.mapper.ShopCarMapper;
import com.zxh.zhenxihuan.service.ShopCarService;
import com.zxh.zhenxihuan.util.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author:geQiang
 * @version:1.0
 * @date:2019/7/31
 * @description:com.zxh.zhenxihuan.controller
 */
@RestController
@CrossOrigin
public class ShopCarController {
    @Resource
    ShopCarMapper shopCarMapper;
    @Resource
    ShopCarService shopCarService;

    @PostMapping("findShopCar")
    public String getAllShopCar(@RequestBody Map maps){
        try {
            Integer num= (Integer) maps.get("page");
            Integer count= (Integer) maps.get("limit");
            Page<ShopCar> pages=shopCarService.page(num,count);
            Map<String,Object> map=new HashMap<>();
            map.put("page",pages);
            System.out.println(pages);
            System.out.println("findAll");
            return JSON.toJSONStringWithDateFormat(map,"yyyy-MM-dd", SerializerFeature.DisableCircularReferenceDetect);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @PostMapping("delShopCar")
    public long delShopCar(@RequestBody Map map){
        Long id = (Long)map.get("id");
//        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+id);
        return shopCarMapper.delShopCar(id);
    }
}
